/**
 * Created by Administrator on 2017/6/13.
 */
angular
    .module('myApp',[])
    .controller('MyController',function ($scope,productData) {
        $scope.productData = productData;
        $scope.order = '';
        $(function () {
           $('.caret').parent().on('click',function () {
                var index = $(this).index();
                var order = '';
                $scope.$apply(function () {
                    if (index == 0){
                        order = 'id';
                    }else if (index == 1){
                        order = 'name';
                    }else if(index == 2){
                        order = 'price';
                    }
                    if ($scope.order == order){
                        $scope.order = '-'+order;
                    }else {
                        $scope.order = order;
                    }
                });
           });
        });
    })
    .service('productData',function () {
        return [
            {
                id : 333,
                name : 'IPhone 7',
                price : 5400
            },
            {
                id : 123,
                name : 'IPhone 6s',
                price : 4000
            },
            {
                id : 216,
                name : 'IPhone 6',
                price : 3000
            },
            {
                id : 2122,
                name : 'IPhone 5s',
                price : 2000
            },
            {
                id : 147,
                name : 'Mac',
                price : 8700
            }
        ];
    });